/**
 * 添加或修改社区信息
 * 
 * @param {}
 *            id
 * @param {}
 *            title
 * @return {}
 */
function addOrUpdateActivityBaby(id, title) {
	var addOrUpdateActivityBabyForm = new Ext.form.FormPanel({
				id : 'addOrUpdateActivityBabyForm',
				frame : true,
				layout : "form",
				buttonAlign : 'center',
				monitorValid : true,
				bodyBorder : false,
				reader : new Ext.data.JsonReader({
							success : 'success',
							root : 'data'
						}, [{
									name : "id"
								}, {
									name : "sex"
								}, {
									name : "content"
								}, {
									name : "isUsable"
								}, {
									name : "createdDate"
								}, {
									name : "createdName"
								}]),
				items : [{
							xtype : 'hidden',
							id : 'activityBabyForm_id',
							name : 'id'
						}, {
							id : 'activityBabyForm_sex',
							xtype : 'localcommonbox',
							anchor : '100%',
							fieldLabel : "<span style='color:#F00'>*</span>性别",
							editable : false,
							hiddenName : "sex",
							allowBlank : false,
							loaclarr : [['0', '男孩'], ['1', '女孩']]
						}, {
							id : 'activityBabyForm_isUsable',
							xtype : 'localcommonbox',
							anchor : '100%',
							fieldLabel : '可用状态',
							editable : false,
							hiddenName : "isUsable",
							loaclarr : [['0', '可用'], ['1', '不可用']],
							value : '0'
						}, {
							id : 'activityBabyForm_content',
							fieldLabel : "内容",
							xtype : "EditorEx",
							height : 350,
							anchor : '100%',
							allowBlank : false,
							blankText : '协议内容不能为空',
							listeners : {
								initialize : function(h) {
								}
							}
						}],
				buttons : [{
							text : '确定',
							formBind : true,
							handler : function() {
								addOrUpdatActivityBaby();
							}
						}, {
							text : "取消",
							handler : function() {
								addOrupdateActivityBabyWindow.close();
							}
						}]
			});
	var addOrupdateActivityBabyWindow = new Ext.Window({
				id : 'addOrUpdateActivityBabyWindow',
				closeAction : 'close',
				title : title,
				closable : true,
				plain : true,
				modal : true,
				width : 700,
				height : 400,
				buttonAlign : 'center',
				autoDestroy : true,
				layout : 'fit',
				items : [addOrUpdateActivityBabyForm],
				listeners : {
					'show' : function() {
						selectActivityBabyUpdateById(id);
					},
					'beforeshow' : function() {
						addOrupdateActivityBabyWindow.center();
					}
				}
			});
	return addOrupdateActivityBabyWindow;

};
/**
 * 查询活动内容信息
 * 
 * @param {}
 *            id
 */
function selectActivityBabyUpdateById(id) {
	if (id != null && id != "undefined") {
		Ext.getCmp("addOrUpdateActivityBabyForm").getForm().load({
			deferredRender : false,
			url : __ctxPath + "/activityManager/selectActivityBabyById",
			params : {
				id : id
			},
			waitTitle : "请稍候",
			waitMsg : "正在载入数据...",
			root : "data",
			success : function(response, options) {
				var data = options.result.data;
				// 性别
				if (data.sex) {
					var sex = Ext.getCmp("activityBabyForm_sex");
					sex.setValue(data.sex); // 隐藏的值
					sex.setRawValue(PmsUtil.activityBabySex(data.sex));// 显示的值
				}
				// 设置是否可用
				if (data.isUsable) {
					var isUsable = Ext.getCmp("activityBabyForm_isUsable");
					isUsable.setValue(data.isUsable); // 隐藏的值
					isUsable.setRawValue(PmsUtil
							.activityBabyIsUsable(data.isUsable));// 显示的值
				}
				Ext.getCmp("activityBabyForm_content").setValue(data.content);// 赋值
			},
			failure : function(f, g) {
				Ext.MessageBox.show({
							title : "操作信息",
							msg : "数据加载失败!",
							buttons : Ext.MessageBox.OK,
							icon : Ext.MessageBox.ERROR
						});
			}
		});
	}
}
/**
 * 添加或修改宝宝内容信息
 */
function addOrUpdatActivityBaby() {
	var ActivityBabyForm = Ext.getCmp("addOrUpdateActivityBabyForm");
	if (ActivityBabyForm.getForm().isValid()) {
		Ext.Msg.confirm("提示框", "确认要保存宝宝内容信息吗?", function(button) {
			if (button == "yes") {
				var content = Ext.getCmp('activityBabyForm_content').getValue();
				ActivityBabyForm.getForm().submit({
					url : __ctxPath
							+ '/activityManager/addOrUpdateActivityBaby',
					params : {
						content : content
					},
					waitTitle : "请稍候",
					waitMsg : "正在提交表单，请稍候......",
					failure : function(response, options) {
						var jsonData = Ext.util.JSON
								.decode(options.response.responseText);
						Ext.MessageBox.show({
									title : "错误提示",
									msg : jsonData.data,
									buttons : Ext.MessageBox.OK,
									icon : Ext.MessageBox.ERROR
								});
					},
					success : function(response, options) {
						var jsonData = Ext.util.JSON
								.decode(options.response.responseText);
						Ext.MessageBox.show({
									title : "信息提示",
									msg : jsonData.data,
									buttons : Ext.MessageBox.OK,
									icon : Ext.MessageBox.INFO
								});
						Ext.getCmp("addOrUpdateActivityBabyWindow").close();
						var gridPanel = Ext.getCmp('ActivityBabyManagerGrid');
						if (typeof(gridPanel) != 'undefined') {
							gridPanel.store.reload();
						}
					}
				});
			}
		});
	}
}